<?php include '_init_.php';?>
<?php
$dtBenzuStyle = new DataTable(constant('DB_TABLE_BENZU_STYLE'));
$dtPhotoSize = new DataTable(constant('DB_TABLE_PHOTO_SIZE'));
$dtGift = new DataTable(constant('DB_TABLE_GIFT'));
$dtCatalog = new DataTable(constant('DB_TABLE_CATALOG'));
$dtCatPhotoSize = new DataTable(constant('DB_TABLE_CATALOG_PHOTO_SIZE'));
$dtCatPhotoSizeFrame = new DataTable(constant('DB_TABLE_CATALOG_PHOTO_SIZE_FRAME'));
$dtCatGift = new DataTable(constant('DB_TABLE_CATALOG_GIFT'));

$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if($act == 'setstatus')
{
	$updateData = array('id'=>$_REQUEST['id'],'is_active'=>$_REQUEST['active']);
	$dtCatalog->save($updateData);
}
if($act == 'delete')
{
	$dtCatalog->remove(intval($_REQUEST['id']));
}
?>
<?php include 'page_header.php';?>
<div id="main"><!-- start #main //-->
<div id="tita"> <!-- start #tita //-->
<?php define('ADMIN_NAVIGATOR_ITEM','預約包套管理');?>
<?php include 'navigator_admin.php';?>
<?php define('ADMIN_MENU_CURRENT_ITEM','包套建立');?>
<?php include 'admin_menu.php';?>
<?php


$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ?intval($_REQUEST['page']):1;
$pageSize = 10;
$catalogList = $dtCatalog->get_list('','name',$pageSize,$pageSize * ($page - 1));
$totalCatalogCount = ceil($dtCatalog->get_count()/$pageSize);

$dtBenzuStyle->primaryKeyAsKey = true;
$benzuStyleMap = $dtBenzuStyle->get_list();

$dtPhotoSize->primaryKeyAsKey = true;
$photoSizeMap = $dtPhotoSize->get_list();

$dtGift->primaryKeyAsKey = true;
$giftMap = $dtGift->get_list();
?>
<div class="clearfix" id="mainf"><!-- start #mainf //-->
<?php foreach($catalogList as $catalogData):?>
<div class="mainf-3">
<ul>
    <li class="maina-1h">
        預約方案<img width="21" height="12" src="images/line3.gif"><?php echo $catalogData['name'];?></li>
         <li class="maina-1h">
        金額<img width="21" height="12" src="images/line3.gif">NT:<?php echo number_format($catalogData['price']);?></li>
      <li class="maina-1g">
        預約類別<img width="21" height="12" src="images/line3.gif"><?php echo $catalogData['type'];?></li>
      <li class="maina-1g">
       數位光碟<img width="21" height="12" src="images/line3.gif"><?php echo $catalogData['disk_number'];?>組
      </li>
        <li class="maina-1g">
        相本<img width="21" height="12" src="images/line3.gif"><?php echo $benzuStyleMap[$catalogData['benzu_style_id']]['name'];?></li>
        <li class="maina-1g">
        拍攝人數（成人）<img width="21" height="12" src="images/line3.gif"><?php echo $catalogData['person_number'];?>人</li>
      <li class="maina-1g">
       造型（成人）<img width="21" height="12" src="images/line3.gif"> <?php echo $catalogData['dress_number'];?>套 </li>
       <li class="maina-1g">
       服裝（成人）<img width="21" height="12" src="images/line3.gif"> <?php echo $catalogData['dress_number'];?>套 </li>
        <li class="maina-1g">
        拍攝人數（小孩）<img width="21" height="12" src="images/line3.gif"><?php echo $catalogData['person_number2'];?>人</li>
      <li class="maina-1g">
       造型（小孩）<img width="21" height="12" src="images/line3.gif"> <?php echo $catalogData['dress_number2'];?>套 </li>
       <li class="maina-1g">
       服裝（小孩）<img width="21" height="12" src="images/line3.gif"> <?php echo $catalogData['dress_number2'];?>套 </li>
       
       <?php
       		//Zoom information
       		$cat_size_list = $dtCatPhotoSize->get_list(sprintf("`catalog_id`=%d",$catalogData['id']));
       		foreach($cat_size_list as $catSizeData)
       		{
       			if(array_key_exists($catSizeData['photo_size_id'],$photoSizeMap))
       			{
       				printf('<li class="maina-1g">放大<img width="21" height="12" src="images/line3.gif">%s 吋 X %d</li>',$photoSizeMap[$catSizeData['photo_size_id']]['name'],$catSizeData['number']);
       			}
       		}
       ?>
       
       <?php
       		$cat_gift_list = $dtCatGift->get_list(sprintf("`catalog_id`=%d",$catalogData['id']));
       		foreach($cat_gift_list as $catGiftData)
       		{
       			if(array_key_exists($catGiftData['gift_id'],$giftMap))
       			{
       				printf('<li class="maina-1g">%s<img width="21" height="12" src="images/line3.gif">%d</li>',$giftMap[$catGiftData['gift_id']]['name'],$catGiftData['number']);
       			}
       		}
       ?>
       <li class="maina-1d"><a href="backstage-edit.php?act=edit&id=<?php echo $catalogData['id'];?>"><img width="61" height="17" src="images/edit-btn.gif"></a>
       <?php if($catalogData['is_active'] == 'N'):?>
        <a href="?act=setstatus&active=Y&id=<?php echo $catalogData['id'];?>"><img width="81" height="17" src="images/edit-start.gif"></a>
       <?php else:?>
        <a href="?act=setstatus&active=N&id=<?php echo $catalogData['id'];?>"><img width="81" height="17" src="images/edit-stop.gif"></a>
       <?php endif;?>
       <a href="?act=delete&id=<?php echo $catalogData['id'];?>" onclick="return confirm('刪除包套？');"><img width="60" height="17" src="images/backstage-btn-7.gif"></a>
       </li>
    </ul>
</div>
<?php endforeach;?>

</div><!-- end #mainf //-->

<div>
<div id="pageh-4"><a href="backstage-edit.php"><img width="78" height="29" src="images/backstage-btn-1.gif"></a></div>
<!-- start #pagea //-->
<?php AppMain::paginationUI($totalCatalogCount,$page,'?page=%d');?>
<!-- end #pagea //-->
</div>

</div><!-- end #tita //-->
</div><!-- end #main //-->
<?php include 'page_footer.php';?>